package com.chb.jblog.web.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.chb.jblog.entity.User;
import com.chb.jblog.service.UserServiceI;
@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private UserServiceI userService;
	private static final Log logger = LogFactory.getLog(UserController.class);
	@RequestMapping("/index")
	public String index(){
		return "index";
	}
	@RequestMapping("/list")
	public String list(ModelMap map){
		List<User> list = userService.setectAll();
		map.put("users", list);
		logger.info(JSON.toJSONString(list));
		return "user/list";
	}
	
	@RequestMapping("/detail/{id}")
	public String detail(@PathVariable("id") Integer id,ModelMap modelMap){
		User user = userService.selectByPrimaryKey(1);
		modelMap.put("user", user);
		return "user/det";
	}
	
}
